import json
import struct
from google.protobuf import json_format
import portal_pb2

with open("pb.txt", 'rb') as f:
    data = f.read()

a, b, c, d = struct.unpack("=Hi71s602s", data)
person = portal_pb2.AuthReq()
person.ParseFromString(c)
print("AuthReq1:", person.AppUUID, person.ChannelID, person.DeviceID, person.AccountID, person.AuthInfo, person.Pwd)

a, b, c, d = struct.unpack("=Hi57s539s", d)
person = portal_pb2.NoticeBoardReq()
person.ParseFromString(c)
print("NoticeBoardReq2:", person.ChannelID, person.DeviceID, person.DeviceType)

a, b, c, d = struct.unpack("=Hi480s53s", d)
person = portal_pb2.NoticeBoardRsp()
person.ParseFromString(c)
x1 = person.NoticeBoardInfoArray
jsonStringRequest1 = json_format.MessageToJson(x1[0])
jsonStringRequest2 = json_format.MessageToJson(x1[1])
a1 = json.loads(jsonStringRequest1)
a2 = json.loads(jsonStringRequest2)
print("NoticeBoardRsp3中数据:")
print(a1)
print(a2)

a, b, c = struct.unpack("=Hi47s", d)
person = portal_pb2.AuthRsp()
person.ParseFromString(c)
x1 = person.Code
x2 = person.Msg
x3 = person.AppUUID
x4 = person.AccountID
x5 = person.AccountName
x6 = person.Token
x7 = person.TokenExpiredTime
x8 = person.OneArea
x9 = person.TokenStr
x10 = person.LoginHost
print("AuthRsp4:", x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)
